package it.unibo.location;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author ale
 * @version 1.0
 * @created 24-ott-2012 00:47:49
 */
public abstract class LocationDevice {

	private List<LocationListener> listeners;

	public LocationDevice(){
		listeners = new CopyOnWriteArrayList<LocationListener>();
	}

	public abstract ILocation getCurrentLocation();

	/**
	 * Returns the speed of the device over ground in meters/second.
	 */
	public abstract float getSpeed();

	/**
	 * Returns the direction of travel in degrees East of true North.
	 */
	public abstract float getBearing();

	public abstract String getName();

	public abstract ILocation createLocation(double latitude,double longitude,double altitude);

	public void addLocationListener(LocationListener listener){
		listeners.add(listener);
	}

	public void removeLocationListener(LocationListener listener){
		listeners.remove(listener);
	}

	protected void fireLocationEvent(){
		LocationEvent event = new LocationEvent(this, getCurrentLocation());
		for (LocationListener locationListener : listeners) {
			locationListener.onLocationChanged(event);
		}
	}

}